<?
class chibiPaintApplet extends bjPaintApplet{

	public function getPluginDescriptors(){
		return array(
			"title" => "Chibi Paint",
			"guid" => "chibiPaintApplet",
			"type" => "paintApplet",
			"version" => "1.0",
			"authors" => array("Marc Schefer"),
			"website" => "http://chibipaint.com",
			"description" => "ChibiPaint applet by Marc Schefer."	
		);			
	}	
		
	public function pluginInit(){
		return array("errorCode" => self::PLUGIN_INIT_SUCCESS, 'msg' => 'Init successfully');
	}
		
	public function pluginEnable($params){
		return array("errorCode" => self::PLUGIN_ENABLE_SUCCESS, 'msg' => 'Plugin enabled.');			
	}
	
	public function pluginDisable($params){
		return array("errorCode" => self::PLUGIN_DISABLE_FAIL, 'msg' => 'You cannot disable this plugin.');	
	}	
	
	public function pluginDestroy($params){
		return array("errorCode" => self::PLUGIN_DESTROY_FAIL, 'msg' => 'You cannot remove this plugin.');	
	}

	public function pluginUpgrade(){
		return array("errorCode" => self::PLUGIN_UPGRADE_NONE, 'msg' => 'Nothing to upgrade.');			
	}
	
	public static function appletSave($params){
		
	}
	
	public static function appletLoad($params){
	
	}	

	/**
	 * Prepares incoming image data for consumption by bjImageStorage::imageStorageSave()
	 * @param Array Depends on the applet and how it sends data
	 * @returns Mixed 
	 * @subreturn String $params:data[i]->extension Image type (ie PNG, JPG)
	 * @subreturn Mixed  $params:data[i]->data Raw image data reflecting the type
	 */	
	public function prepareDataForSave($params){
		$params = $_FILES;
		
	    $img = array();
	    
	    if (isset($params["picture"])){
	    
			//Handle normal file
			$file = $params['picture']['name'];
			$ext = (strpos($file, '.') === FALSE) ? '' : substr($file, strrpos($file, '.')+1);
			$cfile = fopen($params['picture']['tmp_name'], "rb");
			$img["data"][] = fread($cfile, filesize($params['picture']['tmp_name']));
			$img["extension"][] = $ext;
			fclose($cfile);   

			if (isset($params["chibifile"])){	
			  //Handle chibi file
			  $cfile = fopen($params['chibifile']['tmp_name'], "rb");
			  $img["data"][] = fread($cfile, filesize($params['chibifile']['tmp_name']));
			  $img["extension"][] = "chi";
			  fclose($cfile);   
			}
	      
	    }	
	    
	    return $img;
	}
		
}

?>